<?php
/*
 * class.discount.php
 * 商家折扣信息
 * @version 0.1
 * @author samuel
 * @date 2009-05-15
 */
include_once 'class.sellerBase.php';
class seller_discount extends sellerBase {
    private $step;
    private $classname;
    private $tpl_file;

    function  __construct($core) {
        parent::__construct();

        //参数处理
        $this->step = $this->params['step'];
        if(!$this->step) $this->step = "list";
        $this->classname = strtolower(trim(get_class($this)));
        $this->tpl_file = $this->classname . "_" . $this->step . ".html";

        $this->run();
    }

    function run(){
        var_dump($this->step);
        switch($this->step){
            case 'list':
                $page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_info = $this->getSellerDiscountList("", array("SellerDisID"=>"desc"), $arr_limit);
                $arr_lists = $arr_info['list'];
                $pager = $arr_info['pager'];
                $this->core->tpl->assign('arr_lists', $arr_lists);
                $this->core->tpl->assign('pager', $pager);
                break;
            case 'add':
                $sellers = $this->getSellerAllList();
				$this->core->tpl->assign('sellers', $sellers);
                break;
            case 'do_add':
				$info = array();
                $info['SellerID'] = $this->params['SellerID'];
                $info['SellerMsg'] = $this->params['SellerMsg'];
				$info['SellerMsgIs'] = $this->params['SellerMsgIs'];
                $tag = $this->addNewSellerDiscount($info);
                if(!$tag){
                    $this->core->utility->messagePrompt($this->error);
                }
                $this->core->utility->messagePrompt('添加成功!');
                return;
                break;
            case 'edit':
				$sellers = $this->getSellerAllList();
				$this->core->tpl->assign('sellers', $sellers);
                $did = $this->params['did'];
                $discount = $this->getSellerDiscountInfo($did);
				$this->core->tpl->assign('discount', $discount);
                break;
			case 'do_edit':
				$did = $this->params['did'];
				$info['SellerID'] = $this->params['SellerID'];
                $info['SellerMsg'] = $this->params['SellerMsg'];
				$info['SellerMsgIs'] = $this->params['SellerMsgIs'];
				$this->updateInfo('fun_seller_discount', 'SellerDisID', $did, $info);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('更新成功！');
				}
				return;
				break;
			case 'del':
				$did = $this->params['did'];
				$this->delInfo('fun_seller_discount', 'SellerDisID', $did);
				if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
				return;
				break;
			case 'batch_del':
                $ids = $this->params['checkboxes'];
                if(is_array($ids)){
                    foreach($ids as $id){
                        $this->delInfo('fun_seller_discount', 'SellerDisID', $id);
                    }
                }
                if($this->error){
					$this->core->utility->messagePrompt($this->error);
				}else{
					$this->core->utility->messagePrompt('删除成功！');
				}
                return;
                break;
			case 'search':
				$search_seller = $this->params['search_seller'];
				$search_status = $this->params['search_status'];
				$search_url_append = "&step=".$this->step."&search_seller=".$search_seller."&search_status=".$search_status;
				$arr_filter = array();
				if($search_seller){
					$arr_filter[] = array('attr'=>'SellerNameCN', 'value'=>$search_seller, 'match'=>'like', 'join'=>'b');
				}
				if($search_status){
					if($search_status == '显示' ) $status = 1;
						else $status = 0;
					$arr_filter[] = array('attr'=>'SellerMsgIs', 'value'=>$status, 'match'=>'');
				}
				$page = is_numeric($this->params['page']) ? $this->params['page'] : 1;
                $pagesize = 20;
                $current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . $search_url_append;
                $arr_limit = array('page'=>$page, 'pagesize'=>$pagesize, 'url'=>$current_url);
                $arr_info = $this->getSellerDiscountList($arr_filter, array("SellerDisID"=>"desc"), $arr_limit);
                $arr_lists = $arr_info['list'];
                $pager = $arr_info['pager'];
                $this->core->tpl->assign('arr_lists', $arr_lists);
                $this->core->tpl->assign('pager', $pager);
				//共用一个模板
				$this->tpl_file = "seller_discount_list.html";
				break;
        }
        $this->core->tpl->display($this->tpl_file);
    }
}
?>
